﻿
using JZ_UDI.CommonHelper;
using JZ_UDI.DataAccess.DataEntity;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace JZ_UDI
{
    public static class Global
    {
        //厂商代码
        public static string VendorCode = ConfigHelper.GetAppConfig("VendorCode");

        //用户
        public static User UserInfo { get; set; }

        //权限列表
        public static List<PrivilegeList> PriList { get; set; }

        public static List<UserPrivilege> UserPrivileges { get; set; }


        public static string MacAddress;

        public static Logger logger = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// 保存日志到数据库包含自定义字段
        /// </summary>
        /// <param name="level"></param>
        /// <param name="loggerName"></param>
        /// <param name="strMsg"></param>
        public static void SaveLogger(LogLevel level,string loggerName,string strMsg)
        {
            var myLogEventInfo = LogEventInfo.Create(level, loggerName, strMsg);
            myLogEventInfo.Properties["MyCustomField_Mac"] = MacAddress;
            myLogEventInfo.Properties["MyCustomField_UID"] = UserInfo.UserName;
            logger.Log(myLogEventInfo);
        }



        public static string GetMACAddress()
        {
            string macAddress = "";
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    macAddress = nic.GetPhysicalAddress().ToString();
                    break;
                }
            }
            return macAddress;
        }
    }
}
